package com.itheima.college_infomaneger_sys.dao;

import com.itheima.college_infomaneger_sys.domain.Student;

public class StudentDao {
    private static Student[] students = new Student[5];

    public boolean addStudent(Student stu) {

        int num = -1;
        for (int i = 0; i < students.length; i++) {
            if (students[i] == null) {
                num = i;
                break;
            }
        }

        if (num == -1) {
            return false;
        } else {
            students[num] = stu;
            return true;
        }
    }

    public Student[] getAllStudents() {
        return students;
    }

    public int getExistId(String id) {
        int num = -1;
        for (int i = 0; i < students.length; i++) {
            Student stu = students[i];
            if (stu != null && stu.getId().equals(id)) {
                num = i;
                return num;
            }
        }
        return num;
    }

    public void delStudentInfo(int existId) {
        students[existId] = null;
    }
}
